'''
pygeom -- Python Geometric Engine
world -- The World

The world is a GESet, but a very important one. A World will
notify its GEs of registry (it uses Register in place of
Append), and in doing so the GE will recognize the World as
its own World. The World is then referred to by the GE to
perform "World-wide" calculations, such as computing all
intersects or finding the closest GE to a point.

A GE can be in only one World at a time. If a World is asked
to register a GE which already has a World, the "new World"
will ask the GE to unregister the "old World".

Apparently you can make a lot of World jokes when documenting
this. But seriously...
'''

from pygeom import geset

class World(geset.GESet):
    #Just because I am redefining this, it doesn't mean you should
    #use this name. This is ONLY because I can't remove "Append" as
    #a base class method. Use "Register" for clarity.
    def Append(self, ge, init_update=True):
        if ge.World is self:
            raise ValueError('GE %r is already registered in this World %r'%(ge, self))
        if ge.World:
            ge.World.Unregister(ge)
        ge._WorldSet(self)
        self._list.append(ge)
        ge._WorldRegister()
        if init_update:
            ge._WorldUpdate()
    Register=Append
    #Same thing here
    def Remove(self, ge):
        if (not ge.World) or (ge.World is not self):
            raise ValueError('GE %r is not registered in this World %r'%(ge, self))
        ge._WorldUnregister()
        ge._WorldSet(None)
        self._list.remove(ge)
    Unregister=Remove
    def Extend(self, geiter):
        for i in gelist:
            self.Register(i)
    #I'll keep around the set functions because I'm lazy, but you
    #should remember that enforcing disjointness between worlds means
    #that Difference will always return the same set, Symmetric
    #Difference will return the same thing as Union, and Intersection
    #will return an empty set.
